package com.dhf.framework.web.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dhf.framework.base.mybatis.core.page.Pagination;
import com.dhf.framework.common.BaseController;
import com.dhf.framework.web.entity.Projectitem;
import com.dhf.framework.web.service.ProjectitemService;

 /**
 * </b>ProjectitemController<br>项目
 * @author minstar
 * @since2017年04月14日 16时17分00秒 星期五 
 * @version:1.0
 */
@Controller
@RequestMapping("/web/projectitem")
public class ProjectitemController extends BaseController{
		private static Logger LOGGER = LoggerFactory.getLogger(ProjectitemController.class);
	
  		@Autowired
  		private ProjectitemService projectitemService;
  		
  		/**
		  * 
		  * @Title: queryPageList
		  * @Description: 列表页面
		  * @param @param searchEntity
		  * @param @param pagination
		  * @return ModelAndView    返回类型
		  * @throws
		*/
		@RequestMapping(value = "/queryPageList")
		public ModelAndView queryPageList(Projectitem projectitem, Pagination<Projectitem> pagination) {
			LOGGER.debug(ProjectitemController.class.getName()+":开始查询分页数据！");
			ModelAndView mv = new ModelAndView( "web/projectitem/projectitemList" );
			pagination = this.projectitemService.queryPageList( projectitem, pagination );
			mv.addObject( "pagination", pagination );
			return mv;
		}
		
		
		/**
		 * 
		 * @Title: toMerge
		 * @Description: 新增或修改页面
		 * @param @param entity
		 * @return ModelAndView    返回类型
		 * @throws
		 */
		@RequestMapping(value = "/toMerge")
		public ModelAndView toMerge(Projectitem entity){
			ModelAndView mv = new ModelAndView("web/projectitem/projectitemMerge");
			if(entity.getId()!= null){
				Projectitem projectitem =  this.projectitemService.get( entity.getId() ) ;
				mv.addObject("projectitem",projectitem);
			}else{
				mv.addObject("projectitem", new Projectitem());
			}
			return mv;
		}

		/**
		 * 
		* @Title: doMerge
		* @Description: 新增或修改数据 
		* @param @param request
		* @param @param entity
		* @return ModelAndView    返回类型
		* @throws
		 */
		@RequestMapping(value = "/doMerge")
		public ModelAndView doMerge(HttpServletRequest request, Projectitem entity,RedirectAttributes redirectAttributes) {
			if (entity.getId()!=null) {
				LOGGER.debug(ProjectitemController.class.getName()+":开始更新数据！");
				this.addMessage(redirectAttributes, "修改数据成功");
				entity.setModifyTime(new Date());
				this.projectitemService.update( entity );
			} else {
				LOGGER.debug(ProjectitemController.class.getName()+":开始新增数据！");
				entity.setCreateTime(new Date());
				this.projectitemService.add( entity );
				this.addMessage(redirectAttributes, "新增据成功");
			}
			return new ModelAndView( "redirect:/web/projectitem/queryPageList.do" );
		}

		/**
		 * 
		 * @Title: delete
		 * @Description:删除数据
		 * @param @param id
		 * @return ModelAndView    返回类型
		 * @throws
		 */
		@RequestMapping(value = "/delete")
		public ModelAndView delete(Long id,RedirectAttributes redirectAttributes) {
			LOGGER.debug(ProjectitemController.class.getName()+":开始删除数据！");
	        this.projectitemService.delete( id );
	        this.addMessage(redirectAttributes, "删除数据成功");
	        return new ModelAndView( "redirect:/web/projectitem/queryPageList.do" );
		}
}

